/*
 * Copyright (c) 2021 Zsj. All rights reserved.
 */

package com.jzz.crawlerweb.handler.data;

import com.jzz.crawlerweb.handler.generator.TextCaptchaGenerator;

public class CalculationCaptcha extends Captcha<byte[]> {

    @Override
    public String getRaw() {
        return super.getRaw();
    }

    public String getHumanRaw() {
        String[] raw = getRaw().split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < raw.length; i++) {
            if (i % 2 == 0) {
                sb.append(raw[i]);
            } else {
                switch (raw[i]) {
                    case "0":
                        sb.append('+');
                        break;
                    case "1":
                        sb.append('-');
                        break;
                    case "2":
                        sb.append('*');
                        break;
                }
            }
        }
        sb.append("=?");
        return sb.toString();
    }

    @Override
    public byte[] getRendered() {
        return new TextCaptchaGenerator(getHumanRaw()).renderBytes();
    }
}
